<?php
/**
 * ImportController.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-04-08 00:28:01
 * @modified    2023-04-08 00:28:01
 *
 */

namespace App\Http\Controllers;

use App\Services\ImportService;

class ImportController extends BaseModuleController
{
    /**
     * @OA\Post(
     *     path="/import/customer",
     *     tags={"Import"},
     *     summary="导入客户数据",
     *     description="导入客户数据",
     *     operationId="import_customer",
     *     security={{"bearerAuth":{}}},
     *     @OA\RequestBody(
     *         description="表单数据",
     *         @OA\MediaType(
     *             mediaType="multipart/form-data",
     *             @OA\Schema(
     *                 type="object",
     *                 required={"attachment"},
     *                 @OA\Property(property="attachment", description="要导入的excel表格文件， 仅支持xlsx格式", type="file")
     *             )
     *         )
     *     ),
     *     @OA\Response(response=200, description="请求成功"),
     *     @OA\Response(response=401,description="鉴权失败"),
     *     @OA\Response(response=422, description="请求异常")
     * )
     */
    public function customer()
    {
        try {
            $service = new ImportService();
            $data = $service->customer();
            return message("客户数据导入成功", true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    /**
     * @OA\Post(
     *     path="/import/product",
     *     tags={"Import"},
     *     summary="导入设备数据",
     *     description="导入设备数据",
     *     operationId="import_product",
     *     security={{"bearerAuth":{}}},
     *     @OA\RequestBody(
     *         description="表单数据",
     *         @OA\MediaType(
     *             mediaType="multipart/form-data",
     *             @OA\Schema(
     *                 type="object",
     *                 required={"attachment"},
     *                 @OA\Property(property="attachment", description="要导入的excel表格文件， 仅支持xlsx格式", type="file")
     *             )
     *         )
     *     ),
     *     @OA\Response(response=200, description="请求成功"),
     *     @OA\Response(response=401,description="鉴权失败"),
     *     @OA\Response(response=422, description="请求异常")
     * )
     */
    public function product()
    {
        try {
            $service = new ImportService();
            $data = $service->product();
            return message("设备数据导入成功", true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    /**
     * @OA\Post(
     *     path="/import/project_product",
     *     tags={"Import"},
     *     summary="导入项目设备数据",
     *     description="导入项目设备数据",
     *     operationId="import_project_product",
     *     security={{"bearerAuth":{}}},
     *     @OA\RequestBody(
     *         description="表单数据",
     *         @OA\MediaType(
     *             mediaType="multipart/form-data",
     *             @OA\Schema(
     *                 type="object",
     *                 required={"attachment"},
     *                 @OA\Property(property="attachment", description="要导入的excel表格文件， 仅支持xlsx格式", type="file")
     *             )
     *         )
     *     ),
     *     @OA\Response(response=200, description="请求成功"),
     *     @OA\Response(response=401,description="鉴权失败"),
     *     @OA\Response(response=422, description="请求异常")
     * )
     */
    public function project_product()
    {
        try {
            $service = new ImportService();
            $data = $service->projectProducts();
            return message("设备数据导入成功", true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }
}